import { mySignUp } from "../../../api/order"
import { shareAppMessageSet } from "../../../utils/config"
import { dataCollection } from "../../../utils/dataCollection"
import { phoneHide } from "../../../utils/util"

var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: <any>{},
    signUpInfo: <any>{},
    hasSignUp: false,
    themeCode: '',
    headImage: '',
    userPhone: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    //从本地获取当前选择的城市编码
    const themeCode = wx.getStorageSync('themeCode')
    this.setData({
      themeCode,
      headImage:app.globalData.dictMap.get('defaultHeadImage') 
    })
  },
  getData() {
    const userInfo = wx.getStorageSync('userInfo')
    this.setData({
      userInfo,
      userPhone: phoneHide(userInfo.phone)
    })
    console.log('userInfo', userInfo)
    mySignUp().then(res => {
      if (res.result && res.result.productSnapshot) {
        this.setData({
          hasSignUp: true,
          signUpInfo: res.result
        })
      } else {
        this.setData({
          hasSignUp: false
        })
      }
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return { ...shareAppMessageSet() }
  },
  onHide() {
    dataCollection.setPageMapData('leave')
  },
  onUnload() {
    dataCollection.setPageMapData('leave')
  },
  onShow() {
    dataCollection.setPageMapData('enter', '我的报名')
    this.getData()
  },
})